package 蓝桥._2024.商品库存管理;

import java.io.*;
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main3 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] stt = reader.readLine().trim().split(" ");
        int n = Integer.parseInt(stt[0]);
        int m = Integer.parseInt(stt[1]);

        int[][] op = new int[m][2];
        // 区间加法：使用差分数组
        int[] diff = new int[n+3];
        int zero = 0;
        int[] c_1 = new int[n+1]; // 前i项中1的个数
        for (int i = 0; i < m; i++) {
            String[] aStrings = reader.readLine().trim().split(" ");
            op[i][0] = Integer.parseInt(aStrings[0]);
            op[i][1] = Integer.parseInt(aStrings[1]);
            diff[op[i][0]] ++;
            diff[op[i][1]+1] --;
        }

        int[] stock = new int[n+1];
        for (int i = 1; i <= n; i++) {
            stock[i] = stock[i-1] + diff[i];
            c_1[i] = c_1[i-1];
            if(stock[i]==0) zero++;
            if(stock[i]==1) c_1[i]++;
        }
//        System.out.println(Arrays.toString(stock));
//        System.out.println(Arrays.toString(c_0));
//        System.out.println(Arrays.toString(c_1));
        int[] ans = new int[m];
        for (int i = 0; i < m; i++) {
            // 全部0的数量+区间内1的数量
            int t = zero +  (c_1[op[i][1]]-c_1[op[i][0]-1]);
            out.write(t+"\n");
            out.flush();
        }
        reader.close();
        out.close();
    }
}